﻿@model RegisterModel
@using Nop.Web.Framework;
@using Nop.Web.Framework.UI.Captcha;
@using Nop.Web.Models.Customer;
@{
    Layout = "~/Views/Shared/_ColumnsThree.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Register").Text);
}
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                var statesProgress = $("#states-loading-progress");
                statesProgress.show();
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }  
                });
            });
        });
    </script>
}
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <div class="registration-page">
        <div class="page-title">
            <h1>@T("Account.Register")</h1>
        </div>
        <div class="clear">
        </div>
        <div class="body">
            <div class="message-error">
                @Html.ValidationSummary(true)
            </div>
            <div class="clear">
            </div>
            @Html.Partial("_ExternalAuthentication.AssociateMessage")
            <div class="clear">
            </div>
            <div class="section-title">
                @T("Account.YourPersonalDetails")
            </div>
            <div class="clear">
            </div>
            <div class="section-body">
                <table class="table-container">
                    <tbody>
                        @if (Model.GenderEnabled)
                        {
                            <tr class="row">
                                <td class="item-name">
                                    <label>@T("Account.Fields.Gender"):</label>
                                </td>
                                <td class="item-value">
                                    @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "Gender_Male" })
                                    <label class="forcheckbox" for="Gender_Male">@T("Account.Fields.Gender.Male")</label>
                                    @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "Gender_Female" })
                                    <label class="forcheckbox" for="Gender_Female">@T("Account.Fields.Gender.Female")</label>
                                </td>
                            </tr>
                        }
                        <tr class="row">
                            <td class="item-name">
                                @Html.LabelFor(model => model.FirstName):
                            </td>
                            <td class="item-value">
                                @Html.EditorFor(model => model.FirstName)
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.FirstName)
                            </td>
                        </tr>
                        <tr class="row">
                            <td class="item-name">
                                @Html.LabelFor(model => model.LastName):
                            </td>
                            <td class="item-value">
                                @Html.EditorFor(model => model.LastName)
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.LastName)
                            </td>
                        </tr>
                        @if (Model.DateOfBirthEnabled)
                        {
                            <tr class="row">
                                <td class="item-name">
                                    <label>@T("Account.Fields.DateOfBirth"):</label>
                                </td>
                                <td class="item-value">
                                    @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                                Html.FieldNameFor(x => x.DateOfBirthMonth),
                                Html.FieldNameFor(x => x.DateOfBirthYear),
                                DateTime.Now.Year - 110,
                                DateTime.Now.Year,
                                Model.DateOfBirthDay,
                                Model.DateOfBirthMonth,
                                Model.DateOfBirthYear)
                                    @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                                    @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                                    @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                                </td>
                            </tr>
                        }
                        <tr class="row">
                            <td class="item-name">
                                @Html.LabelFor(model => model.Email):
                            </td>
                            <td class="item-value">
                                @Html.EditorFor(model => model.Email)
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.Email)
                            </td>
                        </tr>
                        @if (Model.UsernamesEnabled)
                        {
                            <tr class="row">
                                <td class="item-name">
                                    @Html.LabelFor(model => model.Username):
                                </td>
                                <td class="item-value">
                                    @Html.EditorFor(model => model.Username)
                                    @Html.RequiredHint()
                                    @Html.ValidationMessageFor(model => model.Username)
                                </td>
                            </tr>
                            if (Model.CheckUsernameAvailabilityEnabled)
                            {
                            <tr class="row">
                                <td class="item-name">
                                </td>
                                <td class="item-value">
                                    @Html.Partial("_CheckUsernameAvailability")
                                </td>
                            </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
            <div class="clear">
            </div>
            @if (Model.CompanyEnabled || Model.DisplayVatNumber)
            {
                <div class="section-title">
                    @T("Account.CompanyDetails")
                </div>
                <div class="clear">
                </div>
                <div class="section-body">
                    <table class="table-container">
                        <tbody>
                            @if (Model.CompanyEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.Company):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.Company)
                                        @if (Model.CompanyRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.Company)
                                    </td>
                                </tr>
                            }
                            @if (Model.DisplayVatNumber)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.VatNumber):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.VatNumber)
                                        @Html.ValidationMessageFor(model => model.VatNumber)
                                    </td>
                                </tr>
                                <tr class="row">
                                    <td colspan="2">
                                        <i>@T("Account.Fields.VatNumber.Note")</i>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>                       
                <div class="clear">
                </div>
            }
            @if (Model.StreetAddressEnabled ||
                Model.StreetAddress2Enabled ||
                Model.ZipPostalCodeEnabled ||
                Model.CityEnabled ||
                Model.CountryEnabled)
            {
                <div class="section-title">
                    @T("Account.YourAddress")
                </div>
                <div class="clear">
                </div>
                <div class="section-body">
                    <table class="table-container">
                        <tbody>
                            @if (Model.StreetAddressEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.StreetAddress):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.StreetAddress)
                                        @if (Model.StreetAddressRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.StreetAddress)
                                    </td>
                                </tr>
                            }
                            @if (Model.StreetAddress2Enabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.StreetAddress2):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.StreetAddress2)
                                        @if (Model.StreetAddress2Required)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.StreetAddress2)
                                    </td>
                                </tr>
                            }
                            @if (Model.ZipPostalCodeEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.ZipPostalCode):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.ZipPostalCode)
                                        @if (Model.ZipPostalCodeRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.ZipPostalCode)
                                    </td>
                                </tr>
                            }
                            @if (Model.CityEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.City):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.City)
                                        @if (Model.CityRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.City)
                                    </td>
                                </tr>
                            }
                            @if (Model.CountryEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.CountryId):
                                    </td>
                                    <td class="item-value">
                                        @Html.DropDownList("CountryId", Model.AvailableCountries)
                                    </td>
                                </tr>
                            }
                            @if (Model.CountryEnabled && Model.StateProvinceEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.StateProvinceId):
                                    </td>
                                    <td class="item-value">
                                        @Html.DropDownList("StateProvinceId", Model.AvailableStates)
                                        <span id="states-loading-progress" style="display: none;">@T("Common.Wait...")
                                            <img src='@Url.Content("~/Content/Images/ajax_loader_small.gif")' alt="@T("Common.Wait...")" />
                                        </span>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="clear">
                </div>
            }
            @if (Model.PhoneEnabled || Model.FaxEnabled)
            {
                <div class="section-title">
                    @T("Account.YourContactInformation")
                </div>
                <div class="clear">
                </div>
                <div class="section-body">
                    <table class="table-container">
                        <tbody>
                            @if (Model.PhoneEnabled)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.Phone):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.Phone)
                                        @if (Model.PhoneRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.Phone)
                                    </td>
                                </tr>
                            }
                            @if (Model.FaxEnabled)
                            {                                    
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.Fax):
                                    </td>
                                    <td class="item-value">
                                        @Html.EditorFor(model => model.Fax)
                                        @if (Model.FaxRequired)
                                        {
                                            @Html.RequiredHint()
                                        }
                                        @Html.ValidationMessageFor(model => model.Fax)
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="clear">
                </div>
            }
            @if (Model.NewsletterEnabled)
            {
                <div class="section-title">
                    @T("Account.Options")
                </div>
                <div class="clear">
                </div>
                <div class="section-body">
                    <table class="table-container">
                        <tbody>
                            <tr class="row">
                                <td class="item-name">
                                    @Html.LabelFor(model => model.Newsletter):
                                </td>
                                <td class="item-value">
                                    @Html.EditorFor(model => model.Newsletter)
                                    @Html.ValidationMessageFor(model => model.Newsletter)
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="clear">
                </div>
            }
            @if (Model.AllowCustomersToSetTimeZone)
            {
                <div class="section-title">
                    @T("Account.Preferences")
                </div>
                <div class="clear">
                </div>
                <div class="section-body">
                    <table class="table-container">
                        <tbody>
                            @if (Model.AllowCustomersToSetTimeZone)
                            {
                                <tr class="row">
                                    <td class="item-name">
                                        @Html.LabelFor(model => model.TimeZoneId):
                                    </td>
                                    <td class="item-value">
                                        @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones)
                                        @Html.ValidationMessageFor(model => model.TimeZoneId)
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
                <div class="clear">
                </div>
            }
            <div class="section-title">
                @T("Account.YourPassword")
            </div>
            <div class="clear">
            </div>
            <div class="section-body">
                <table class="table-container">
                    <tbody>
                        <tr class="row">
                            <td class="item-name">
                                @Html.LabelFor(model => model.Password):
                            </td>
                            <td class="item-value">
                                @Html.EditorFor(model => model.Password)
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.Password)
                            </td>
                        </tr>
                        <tr class="row">
                            <td class="item-name">
                                @Html.LabelFor(model => model.ConfirmPassword):
                            </td>
                            <td class="item-value">
                                @Html.EditorFor(model => model.ConfirmPassword)
                                @Html.RequiredHint()
                                @Html.ValidationMessageFor(model => model.ConfirmPassword)
                            </td>
                        </tr>
                        @if (Model.DisplayCaptcha)
                        {
                            <tr class="row">
                                <td class="captcha-box" colspan="2">
                                    @Html.Raw(Html.GenerateCaptcha())
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="clear">
            </div>
            <div class="buttons">
                <input type="submit" class="registernextstepbutton" id="register-button" value="@T("Account.Register.Button")" name="register-button" />
            </div>
        </div>
    </div>
}